#include <cstdio>
#include <algorithm>

using namespace std;

int main( )
{
    int i, n, a[ 1001 ], s, ac;
    while ( scanf("%d", &n) != EOF )
    {
        for ( i = 0; i < n; i++ )
            scanf("%d", &a[ i ]);
        sort( a, a + n );
        ac = s = 0;
        for ( i = 0; i < n; i++ )
        {
            if ( a[ i ] <= s )
                continue;
            if ( ac < ( a[ i ] - s ) * ( n - i ) )
                ac = ( a[ i ] - s ) * ( n - i );
//            s += a[ i ];
        }
        printf("%d\n", ac);
    }
    return 0;
}
